home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_srgp.lha / srgp / src / srgplocal.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-09  |  11.4 KB  |  468 lines

  1.  
  2. /** IMPORTANT INFORMATION FOR MACINTOSH DEVELOPERS/ADMINISTRATORS 
  3. The source code for the Macintosh version of SRGP uses conditional compilation
  4. to support both the original QuickDraw and Color QuickDraw.
  5. You must edit the file "ChooseWhichQuickDraw.h"; see instructions therein.
  6. **/
  7.  
  8. #ifdef X11
  9. #include <X11/Xlib.h>
  10. #include <X11/Xutil.h>
  11. #include <X11/Xos.h>
  12. #include <X11/cursorfont.h>
  13. #ifdef sun
  14. #include <malloc.h>
  15. #else
  16. extern char *malloc();
  17. #endif
  18. #endif
  19.  
  20. #define point            srgp__point
  21. #define rectangle        srgp__rectangle
  22. #define attribute_group  srgp__attribute_group
  23.  
  24. #define REPORT_ERROR   SRGP__error
  25. #define NON_FATAL 0
  26. #define FATAL     1
  27.  
  28. #include "macros.h"
  29.  
  30. #include "srgp_sphigs.h"
  31.  
  32. #include "srgppublic.h"
  33. #include "srgp_errtypes.h"
  34. #include "assert.h"
  35.  
  36.  
  37.  
  38.  
  39. #ifdef SRGP_BOSS
  40. #define DECLARE
  41. boolean    srgp__traceDisabled=TRUE;
  42. boolean    srgp__userDebugAidsDisabled=FALSE;
  43. boolean srgp__enabled=FALSE;
  44. boolean srgp__blockedWaitEnabled=FALSE;
  45. #else
  46. #define DECLARE extern
  47. extern boolean srgp__traceDisabled;
  48. extern boolean srgp__userDebugAidsDisabled;
  49. extern boolean srgp__enabled;
  50. extern boolean srgp__blockedWaitEnabled;
  51. #endif
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. /** THE CANVAS DATABASE
  61. Each canvas is described with a "canvas_spec" record, containing
  62. the dimensions of the canvas, the current value of all the
  63. attributes (stored in a group), and the vdi bitmap index.
  64.  
  65. When canvas X becomes active, a copy of the database spec for X
  66. is put into the global variable "current_active_canvas_spec".  
  67. This global's fields are changed
  68. as activity occurs as long as X remains
  69. active; the database spec's fields therefore becomes obsolete. 
  70. When canvas X becomes inactive, the global's value is copied
  71. into the database spec for X, thus updating the database, correcting
  72. the temporary obsolescence.
  73. **/
  74.  
  75. #ifdef X11
  76.    typedef union {
  77.       XID        xid;     /* FOR ANY CANVAS */
  78.       Window     win;     /* ONLY FOR 0th CANVAS */
  79.       Pixmap     bitmap;  /* FOR ALL OTHER CANVASES */
  80.    }
  81.    drawable_type;
  82. #endif
  83.  
  84. #ifdef THINK_C
  85. typedef void *grafptr;
  86.    typedef union {
  87.       grafptr    xid;     /* FOR ANY CANVAS */
  88.       WindowPtr  win;     /* ONLY FOR 0th CANVAS */
  89.       grafptr    bitmap;  /* FOR ALL OTHER CANVASES */
  90.    }
  91.    drawable_type;
  92. #endif
  93.  
  94. #define srgpx__screenwin        (srgp__canvasTable[0].drawable.win)
  95.  
  96.  
  97. typedef struct {
  98.    int             max_xcoord, max_ycoord;
  99.    attribute_group     attributes;
  100.    drawable_type    drawable;
  101. #ifdef X11
  102.    GC         gc_frame, gc_fill;
  103. #endif
  104. #ifdef THINK_C
  105.    int     transfermode_frame, transfermode_fill;
  106.    Pattern *pat_frame, *pat_fill;
  107. #endif
  108. }
  109. canvas_spec;
  110.  
  111. DECLARE int        srgp__curActiveCanvasId;
  112. DECLARE canvas_spec    srgp__curActiveCanvasSpec;
  113. DECLARE canvas_spec    *srgp__canvasTable;
  114.  
  115. void SRGP__setCanvasDefaults (void);
  116. void SRGP__reactToScreenResize (int newwidth, int newheight);
  117. void SRGP__forceScreenResize (int newwidth, int newheight);
  118.  
  119.  
  120.  
  121.  
  122.  
  123. /** THE PATTERN DATABASES
  124. In X11:  Each pattern index maps into a pointer to an X Pixmap.
  125. In Mac:  bitpats and pixpats will have to be quite different!
  126. **/
  127.  
  128. #ifdef X11
  129. typedef Pixmap                pattern_table_entry, pixpat_table_entry;
  130. #endif
  131.  
  132. #ifdef THINK_C
  133. typedef Pattern                pattern_table_entry;
  134. typedef PixPatHandle        pixpat_table_entry;
  135. #endif
  136.  
  137. DECLARE pattern_table_entry    *srgp__bitmapPatternTable;
  138. DECLARE pixpat_table_entry    *srgp__pixmapPatternTable;
  139.  
  140. extern void SRGP__initDefaultPatterns (void);
  141.  
  142.  
  143.  
  144.  
  145. /** THE CURSOR DATABASE
  146. Each entry maps to a cursor resource.
  147. **/
  148.  
  149. #ifdef X11
  150.    typedef Cursor    cursorInfo;
  151. #endif
  152.  
  153. #ifdef THINK_C
  154.    typedef CursHandle    cursorInfo;
  155. #endif
  156.  
  157. DECLARE cursorInfo    *srgp__cursorTable;
  158.  
  159. extern void SRGP__initCursorTable (void);
  160.  
  161.  
  162.  
  163.  
  164. /** THE FONT DATABASE
  165. X11: A fontInfo item that is NULL represents an unused entry.
  166. Mac: txFont number -1 represents an unused entry.
  167. Initially, only one entry (the one indexed 0) is used.
  168. **/
  169.  
  170. #ifdef X11
  171.    typedef XFontStruct            *fontInfo;
  172. #define SRGP_DEFAULT_FONT_0         "8x13"
  173. #endif
  174.  
  175. #ifdef THINK_C
  176.    typedef struct {
  177.       int txFont, txSize;
  178.       Style txFace;
  179.    } fontInfo;
  180. #endif
  181.  
  182. DECLARE fontInfo    *srgp__fontTable;
  183.  
  184. void SRGP__initFont (void);
  185.  
  186.  
  187.  
  188.  
  189. /** INPUT
  190. **/
  191.  
  192. /* locator measure */
  193. DECLARE srgp__deluxe_locator_measure 
  194.                 srgp__cur_locator_measure, srgp__get_locator_measure;
  195. DECLARE int srgp__cur_Xcursor_x, srgp__cur_Xcursor_y;   /* IN X/Mac COORDS */
  196. DECLARE int     srgp__cur_locator_button_mask;
  197.  
  198. DECLARE boolean srgp__dirty_location;  
  199. /* "dirty" bool is used only when: 1) in sample mode and 2) rubber echo off */
  200.  
  201. /* locator echo */
  202. DECLARE int         srgp__cur_locator_echo_type;
  203. DECLARE srgp__point     srgp__cur_locator_echo_anchor;
  204. DECLARE int         srgp__cur_cursor;
  205.  
  206. /* keyboard measure */
  207. DECLARE srgp__deluxe_keyboard_measure 
  208.                 srgp__cur_keyboard_measure,
  209.                 srgp__get_keyboard_measure;
  210. DECLARE int    srgp__cur_keyboard_measure_length;  /* not buffer length! */
  211. DECLARE int     srgp__cur_keyboard_processing_mode;
  212.  
  213. /* keyboard echo */
  214. DECLARE int         srgp__cur_keyboard_echo_font;
  215. DECLARE int         srgp__cur_keyboard_echo_color;
  216. DECLARE srgp__point    srgp__cur_keyboard_echo_origin;
  217.  
  218. /* TIMESTAMP FOR EVENT THAT IS SUBJECT TO GET */
  219. DECLARE int srgp__get_timestamp;
  220.  
  221. DECLARE int srgp__cur_mode[4];   /* one for each device, including NO_DEVICE */
  222. DECLARE int srgp__device_at_head_of_queue;
  223.  
  224. void    SRGP__initInputModule (void);
  225. void    SRGP__initInputDrivers (void);
  226. void    SRGP__activateDevice (int device);
  227. void    SRGP__deactivateDevice (int device);
  228. int      SRGP__handleRawEvents (boolean in_waitEvent_call, boolean forever);
  229. void    SRGP__initEchoModule (void);
  230. void    SRGP__enableLocatorRubberEcho (void);
  231. void    SRGP__disableLocatorRubberEcho (void);
  232. void    SRGP__updateLocatorRubberEcho (void);
  233. void    SRGP__updateLocatorRubberAnchor (void);
  234. void    SRGP__enableLocatorCursorEcho (void);
  235. void    SRGP__disableLocatorCursorEcho (void);
  236. void    SRGP__updateLocatorCursorShape (void);
  237. void    SRGP__updateRawCursorPosition (void);
  238. void    SRGP__enableKeyboardEcho (void);
  239. void    SRGP__disableKeyboardEcho (void);
  240. void    SRGP__updateKeyboardEcho (void);
  241. void    SRGP__updateKeyboardEchoAttributes (void);
  242.  
  243.  
  244.  
  245.  
  246. /** MARKERS **/
  247.  
  248. void SRGP__drawSquareMarker (int x, int y);
  249. void SRGP__drawCircleMarker (int x, int y);
  250. void SRGP__drawXMarker (int x, int y);
  251.  
  252.  
  253. /** ERRORS **/
  254. #ifdef THINK_C
  255. void ReportSpecialError (char *message, boolean is_fatal);
  256.  
  257. /* We hide this from gnu's compiler, which doesn't understand it. */
  258. void SRGP__error (int errtype, ...);
  259. #endif
  260.  
  261. extern errorHandlingMode srgp__curErrHndlMode;
  262.  
  263.  
  264. /** COLOR **/
  265. DECLARE int         srgp__available_depth;    /* usually 8 or 1 */
  266. DECLARE unsigned long     srgp__max_pixel_value;    /* based on avail_depth */
  267. DECLARE int        srgp__application_depth;  /* specified by appl */
  268. DECLARE int        srgp__base_colorindex;    /* explained in color_X11.c */
  269.  
  270. #ifdef X11
  271. DECLARE int        srgp__visual_class;
  272. #define XBLACK        BlackPixel(srgpx__display,srgpx__screen)
  273. #define XWHITE        WhitePixel(srgpx__display,srgpx__screen)
  274. #define XCOLOR(I)    (I == 0 ? XWHITE : (I == 1 ? XBLACK : I))
  275.  
  276. #define COLORINDEX(c) \
  277.     ( (unsigned long)(c) | (unsigned long)srgp__base_colorindex )
  278. #endif
  279. #ifdef THINK_C
  280. #define COLORINDEX(c)   ((int)(c|srgp__base_colorindex))
  281. #endif
  282.     
  283. void SRGP__initColor (int requested_planes);
  284. void SRGP__cleanupColor (void);
  285. void SRGP__activateApplColorTable (void);
  286. void SRGP__deactivateApplColorTable (void);
  287.  
  288.  
  289.  
  290. /** LOW-LEVEL GRAPHICS **/
  291. void SRGP__initGraphicsDevice 
  292.    (char *name, int requested_planes, boolean debugasap);
  293. void SRGP__cleanupMacMemory (void);
  294.  
  295.  
  296. /** STORAGE OF VERTEX LISTS
  297. Needed by the X version of output.c
  298. **/
  299. #ifdef X11
  300. DECLARE XPoint *Xformat_vertices;
  301. #endif
  302.  
  303.  
  304. #ifdef THINK_C
  305. /** MAC UTILITIES **/
  306. Rect FIXED_RECT (int lx, int by, int rx, int ty);
  307. #endif
  308.  
  309.  
  310. DECLARE funcptr         srgp__resizeCallback;
  311.  
  312.  
  313. #ifdef X11
  314. DECLARE Display        *srgpx__display;
  315. DECLARE int         srgpx__screen;
  316. DECLARE Colormap     srgpx__colormap;
  317. #endif
  318.  
  319.  
  320. #ifdef THINK_C
  321. DECLARE WindowPtr    srgpmac__cwindow;
  322. DECLARE MenuHandle    srgpmac__applemenu, srgpmac__srgpmenu;
  323. #define Time   long
  324. #endif
  325.  
  326.  
  327. /** TIMESTAMPS **/
  328.  
  329. #ifdef X11
  330. #define rawgranularity  1000  /* per second */
  331. #endif
  332.  
  333. #ifdef THINK_C
  334. #define rawgranularity 60 /* per second */
  335. #endif
  336.  
  337. DECLARE Time        srgpx__starttime, srgpx__cur_time;
  338.  
  339. #undef DECLARE
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351. /** TRACING AND DEBUGGING MACROS
  352. **/
  353.  
  354. #define DEBUG_AIDS      if(!srgp__userDebugAidsDisabled)
  355.  
  356. #define SRGP_trace    if(!srgp__traceDisabled)fprintf
  357.  
  358. #define LeaveIfNonFatalErr()   \
  359.    if(SRGP_errorOccurred)return
  360.  
  361. #define srgp_check_system_state()    \
  362.    if(!srgp__enabled)  SRGP__error(ERR_NOT_ENABLED)
  363.  
  364. #define srgp_check_rectangle(LX, BY, RX, TY)        \
  365.    if(!((LX<=RX)&&(BY<=TY)))  SRGP__error(ERR_BAD_RECT, LX, BY, RX, TY)
  366.  
  367. #define srgp_check_font_index(F)    \
  368.    if(!((F>=0)&&(F<=MAX_FONT_INDEX)))    \
  369.       SRGP__error(ERR_BAD_FONT_INDEX,F)
  370.  
  371. #ifdef X11
  372. #define srgp_check_extant_font(F)    \
  373.    if(!((F>=0)&&(F<=MAX_FONT_INDEX)&&(srgp__fontTable[F])))    \
  374.       SRGP__error(ERR_UNKNOWN_FONT,F)
  375. #endif
  376. #ifdef THINK_C
  377. #define srgp_check_extant_font(F)    \
  378.    if(!((F>=0)&&(F<=MAX_FONT_INDEX)&&(srgp__fontTable[F].txFont!=(-1))))    \
  379.       SRGP__error(ERR_UNKNOWN_FONT,F)
  380. #endif
  381.  
  382. #define srgp_check_poly_item_count(C)    \
  383.    if(!(F>0))  SRGP__error(ERR_BAD_POLY_ITEM_COUNT,C)
  384.  
  385. #define srgp_check_marker_style(MS)        \
  386.    if(!((MS>=0)&&(MS<NUMBER_OF_MARKER_STYLES)))  \
  387.       SRGP__error(ERR_BAD_MARKER_STYLE,MS)
  388.  
  389. #define srgp_check_marker_size(MS)        \
  390.    if(!(MS>0))\
  391.       SRGP__error(ERR_BAD_MARKER_SIZE,MS)
  392.  
  393. #define srgp_check_line_style(LS)        \
  394.    if(!((LS>=CONTINUOUS)&&(LS<=DOT_DASHED)))  \
  395.       SRGP__error(ERR_BAD_LINE_STYLE,LS)
  396.  
  397. #define srgp_check_line_width(LW)        \
  398.    if(!(LW>0))\
  399.       SRGP__error(ERR_BAD_LINE_WIDTH,LW)
  400.  
  401. #define srgp_check_write_mode(WM)        \
  402.    if(!((WM>=WRITE_REPLACE)&&(WM<=WRITE_AND)))\
  403.       SRGP__error(ERR_BAD_WRITE_MODE,WM)
  404.  
  405. #define SRGP_correct_color(C)        \
  406.    if(C>srgp__max_pixel_value) \
  407.       C = srgp__max_pixel_value;
  408.  
  409. #define srgp_check_pixel_value(C,STR)        \
  410.    if(C>srgp__max_pixel_value) \
  411.       SRGP__error(ERR_BAD_PIXEL_VALUE,STR,C)
  412.  
  413. #define srgp_check_fill_style(F)    \
  414.    if(!((F>=SOLID)&&(F<=BITMAP_PATTERN_OPAQUE)))\
  415.       SRGP__error(ERR_BAD_FILL_STYLE,F)
  416.  
  417. #define srgp_check_pattern_table_entry(E) \
  418.    if(E==0) SRGP__error(ERR_BAD_PATTERN_TABLE_ENTRY)
  419.  
  420. #define srgp_check_pattern_index(P)    \
  421.    if(!((P>=0)&&(P<=MAX_PATTERN_INDEX)))  SRGP__error(ERR_BAD_PATTERN_ID,P)
  422.  
  423. #define srgp_check_cursor_index(P)    \
  424.    if(!((P>=0)&&(P<=MAX_CURSOR_INDEX)))  SRGP__error(ERR_BAD_CURSOR_ID,P)
  425.  
  426. #define srgp_check_extant_canvas(CV)    \
  427.    if(!(((CV>=0)||(CV<=MAX_CANVAS_INDEX))&&\
  428.         (srgp__canvasTable[CV].drawable.bitmap)))\
  429.       SRGP__error(ERR_CANVAS_NOT_OPEN,CV)
  430.  
  431. #define srgp_check_device(D)    \
  432.    if(!((D>=KEYBOARD)&&(D<=LOCATOR)))  SRGP__error(ERR_BAD_DEVICE,D)
  433.  
  434. #define srgp_check_mode(D)    \
  435.    if(!((D>=INACTIVE)&&(D<=EVENT)))  SRGP__error(ERR_BAD_MODE,D)
  436.  
  437. #define srgp_check_polygon_list_size(D)    \
  438.    if((D<3)||(D>MAX_POINTLIST_SIZE))  SRGP__error(ERR_POINTLIST_SIZE,D)
  439.  
  440. #define srgp_check_polymarker_list_size(D)    \
  441.    if((D<0)||(D>MAX_POINTLIST_SIZE))  SRGP__error(ERR_POINTLIST_SIZE,D)
  442.  
  443. #define srgp_check_polyline_list_size(D)    \
  444.    if((D<2)||(D>MAX_POINTLIST_SIZE))  SRGP__error(ERR_POINTLIST_SIZE,D)
  445.  
  446. #define srgp_check_event_type(EVTYP)  \
  447.    if(!(srgp__device_at_head_of_queue==EVTYP))  SRGP__error(ERR_BAD_GET)
  448.  
  449. #define srgp_check_locator_echo_type(MS)    \
  450.    if(!((MS>=NO_ECHO)&&(MS<=RUBBER_RECT))) \
  451.       SRGP__error(ERR_BAD_LOC_ECHO_TYPE,MS)
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458. /** MACROS
  459. **/
  460.  
  461. #define FIXED(yy)    \
  462.     (srgp__curActiveCanvasSpec.max_ycoord-(yy))
  463. #define SCREENFIXED(yy)    \
  464.     (srgp__canvasTable[0].max_ycoord-(yy))
  465.  
  466. #define PUSH_TRACE     srgp__userDebugAidsDisabled++
  467. #define POP_TRACE       srgp__userDebugAidsDisabled--
  468.